---
title: "Tuple"
description: "Tuple types and values in ReScript"
canonical: "/docs/manual/tuple"
section: "Language Features"
order: 5
---

# Tuple

Tuples are a ReScript-specific data structure that don't exist in JavaScript. They are:

- immutable
- ordered
- fix-sized at creation time
- heterogeneous (can contain different types of values)

<CodeTab labels={["ReScript", "JS Output"]}>

```res example
let ageAndName = (24, "Lil' ReScript")
let my3dCoordinates = (20.0, 30.5, 100.0)
```

```js
var ageAndName = [24, "Lil' ReScript"];
var my3dCoordinates = [20.0, 30.5, 100.0];
```

</CodeTab>

Tuples' types can be used in type annotations as well. Tuple types visually resemble tuples values.

<CodeTab labels={["ReScript", "JS Output"]}>

```res prelude
let ageAndName: (int, string) = (24, "Lil' ReScript")
// a tuple type alias
type coord3d = (float, float, float)
let my3dCoordinates: coord3d = (20.0, 30.5, 100.0)
```

```js
var ageAndName = [24, "Lil' ReScript"];
var my3dCoordinates = [20.0, 30.5, 100.0];
```

</CodeTab>

**Note**: there's no tuple of size 1. You'd just use the value itself.

## Usage

To get a specific member of a tuple, destructure it:

<CodeTab labels={["ReScript", "JS Output"]}>

```res example
let (_, y, _) = my3dCoordinates // now you've retrieved y
```

```js
var y = 30.5;
```

</CodeTab>

The `_` means you're ignoring the indicated members of the tuple.

Tuples aren't meant to be updated mutatively. You'd create new ones by destructuring the old ones:

<CodeTab labels={["ReScript", "JS Output"]}>

```res example
let coordinates1 = (10, 20, 30)
let (c1x, _, _) = coordinates1
let coordinates2 = (c1x + 50, 20, 30)
```

```js
var coordinates1 = [10, 20, 30];
var c1x = 10;
var coordinates2 = [60, 20, 30];
```

</CodeTab>

## Tips & Tricks

You'd use tuples in handy situations that pass around multiple values without too much ceremony. For example, to return many values:

<CodeTab labels={["ReScript", "JS Output"]}>

```res
let getCenterCoordinates = () => {
  let x = doSomeOperationsHere()
  let y = doSomeMoreOperationsHere()
  (x, y)
}
```

```js
function getCenterCoordinates(param) {
  var x = doSomeOperationsHere(undefined);
  var y = doSomeMoreOperationsHere(undefined);
  return [x, y];
}
```

</CodeTab>

Try to keep the usage of tuple **local**. For data structures that are long-living and passed around often, prefer a **record**, which has named fields.
